package com.qf.studentmanager.config;

import com.mchange.v2.c3p0.ComboPooledDataSource;

import java.sql.Connection;
import java.sql.SQLException;

public class DBConfig {
   private static  ComboPooledDataSource comboPooledDataSource = new ComboPooledDataSource();
    private static ThreadLocal<Connection> threadLocal = new ThreadLocal<>();

    public static Connection getConnection (){
        Connection connection = threadLocal.get();
        if (connection == null){
            try {
                connection = comboPooledDataSource.getConnection();
                threadLocal.set(connection);
                return  connection;
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }

        return connection;
    }

}
